<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp" %>

<html>

<head>
    <base href="<%=basePath%>">
    <title>用户个人安全页面</title>
    <script src="<%=basePath%>component/layout.js"></script>
    <script src="<%=basePath%>component/toolbar.js"></script>
    <script type="text/javascript" src="<%=basePath%>dwrsystem/interface/userService.js"></script> 
	<script type="text/javascript" src="<%=basePath%>dwrsystem/engine.js"></script>
	<script>
	var dhxLayout = createLayoutNormal('1C',false,true);
	
	$(function(){
		configLayout();
	});
	
	function configLayout(){
		var a = dhxLayout.cells('a');
		a.hideHeader();
		a.setText('主页面');
		a.fixSize(true, true);
		createToolbarFromDHXLayoutCell(a,function(toolbar){
		    toolbar.addText("info", 1, "操作:");
		    toolbar.addSeparator("sep1", 2);
		    toolbar.addButton("submit", 5, "提交", "save.gif", "save_dis.gif");
		    toolbar.attachEvent("onClick", function(id) {
		    	if(id == 'submit'){
		    		submitUpdatePassword();
		    	}
		    });
		});
		a.attachObject('dataObj');
	}
	
	function validatePassword(){
		var  passwordWrong = document.getElementById('passwordWrong') ;
		passwordWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/editWaitingImg.gif" />';
		var password = document.getElementById('password').value;
		if(trim(password)==''){passwordWrong.innerHTML='不能为空';return false;}
		
		userService.validatePassword({loginPassword:password, userMainId:'${user.userMainId}'}, function(data){
			if(data == 0){
				document.getElementById('validateRightConfirmPassword').value="0";
				passwordWrong.innerHTML='密码输入错误';
			}
			else{
				document.getElementById('validateRightPassword').value="1";
				passwordWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/ok.png" />';
			}
		});
	}
	
	function validateNewPassword(){
		var  newPasswordWrong = document.getElementById('newPasswordWrong') ;
		newPasswordWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/editWaitingImg.gif" />';
		var newPassword = document.getElementById('newPassword').value;
		if(trim(newPassword)==''){newPasswordWrong.innerHTML='不能为空';return false;}
		
		var  confirmPassword = document.getElementById('confirmPassword') ;
		if(confirmPassword != ''){
			if(confirmPassword != newPassword){
				document.getElementById('validateRightConfirmPassword').value="0";
				document.getElementById('confirmPasswordWrong').innerHTML='两次密码输入不一致';
			}
		}
		document.getElementById('validateRightNewPassword').value="1";
		newPasswordWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/ok.png" />';
	}
	
	function validateConfirmPassword(){
		var  confirmPasswordWrong = document.getElementById('confirmPasswordWrong') ;
		confirmPasswordWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/editWaitingImg.gif" />';
		var confirmPassword = document.getElementById('confirmPassword').value;
		if(trim(confirmPassword)==''){confirmPasswordWrong.innerHTML='不能为空';return false;}
		
		var newPassword = document.getElementById('newPassword').value;
		if(trim(newPassword)!=''){
			if(newPassword != confirmPassword){
				document.getElementById('validateRightConfirmPassword').value="0";
				confirmPasswordWrong.innerHTML='两次密码输入不一致';
				return false;
			}
		}
		document.getElementById('validateRightConfirmPassword').value="1";
		confirmPasswordWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/ok.png" />';
	}
	
	function submitUpdatePassword(){
		var results = document.getElementsByName("validateRight");
		for(var i=0;i<results.length;i++){
			var r = results[i];
			if(r.value == 0){
				myAlert('密码表单填写不正确');
				return false;
			}
		}
		var newPassword = document.getElementById('newPassword').value;
		try{
			userService.updateTUserByPK({loginPassword:newPassword, userMainId:'${user.userMainId}'});
			myAlert('更改密码成功,请牢记密码');
			document.getElementById('password').value='';
			document.getElementById('newPassword').value='';
			document.getElementById('confirmPassword').value='';
			document.getElementById('validateRightPassword').value='0';
			document.getElementById('validateRightNewPassword').value='0';
			document.getElementById('validateRightConfirmPassword').value='0';
			
		}catch(ex){myAlert('更改密码失败');}
	}
	</script>    
</head>

<body>
	<div id="dataObj" class="formlayout" style="width:100%;height:100%;">
		<table>
			<tr>
				<th>原密码</th>
				<td>
					<input onblur="validatePassword();" type="password" name="password" id="password" maxlength="20"/>
					<span class="enterInput">*</span> <span id="passwordWrong" class="enterInput"></span>
					<input type="hidden" name="validateRight"  id="validateRightPassword" value="0">
				</td>
			</tr>
			<tr>
				<th>新密码</th>
				<td>
					<input onblur="validateNewPassword();" type="password" name="newPassword" id="newPassword" maxlength="20"/>
					<span class="enterInput">*</span> <span id="newPasswordWrong" class="enterInput"></span>
					<input type="hidden" name="validateRight" id="validateRightNewPassword" value="0">
				</td>
			</tr>
			<tr>
				<th>确认新密码</th>
				<td>
					<input onblur="validateConfirmPassword();" type="password" name="confirmPassword" id="confirmPassword" maxlength="20"/>
					<span class="enterInput">*</span> <span id="confirmPasswordWrong" class="enterInput"></span>
					<input type="hidden" name="validateRight"  id="validateRightConfirmPassword" value="0">
				</td>
			</tr>
		</table>
	</div>
</body>

</html>
